home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 09 - 1993 / 09.08 Aug 93 / AppleScript App-Folder Watcher / Simple Folder Watcher .txt next >
Encoding:
Text File  |  1993-06-28  |  1.2 KB  |  36 lines  |  [TEXT/ToyS]

  1. -- Folder Watcher, a simple agent example.
  2. -- This script should be built as a stay-open script application.
  3.  
  4. property targetPath : "" -- path to target folder
  5.  
  6. property targetFolder : 0 -- alias to target folder (set at startup)
  7. property modDate : 0 -- modification date of folder when last we checked
  8.  
  9. on run
  10.     -- Since you probably don't have your drop folder in the same place I do,
  11.     -- I modified the script to ask for it the first time it's run. Clever, no?  —Jens
  12.     if length of targetPath is 0 then
  13.         display dialog "Please enter the path to the folder I should watch:" ¬
  14.             default answer ""
  15.         set targetPath to the text returned of the result
  16.     end if
  17.     set targetFolder to alias targetPath -- get an alias to the folder
  18. end run
  19.  
  20. on idle
  21.     set newModDate to modification date of (info for targetFolder)
  22.     if modDate = 0 or newModDate > modDate then
  23.         set modDate to newModDate
  24.         folderChanged(targetFolder)
  25.     end if
  26.     return 3 -- Idle time in seconds
  27. end idle
  28.  
  29. on folderChanged(f)
  30.     beep
  31.     -- Put anything you want here, and it'll run whenever the folder is modified.
  32.     -- See the “What's New?” sample script for a more sophisticated example,
  33.     -- which figures out what files have been added and displays their names
  34.     -- to the user.
  35. end folderChanged
  36.